<script>
	import util from "util/textUtil.js"
	export default {
		globalData: {
			baseUrl: "http://yihuhealth.com:8080/api/"
		},
		onLaunch: function() {
			var ua = window.navigator.userAgent.toLowerCase();
			//判断是不是微信
			if (ua.match(/MicroMessenger/i) == 'micromessenger') {
				this.getWxCode();
			}
			//判断是不是支付宝
			else if (ua.match(/AlipayClient/i) == 'alipayclient') {
				this.getAilCode();
			}
		},
		methods: {
			getWxCode: function() {
				let code = util.getUrlParam("code"); //是否存在code
				let local = window.location.href;
				let Appid = "wxa52403bb7226214b";
				if (code == null || code === "") {
					window.location.href =
						"https://open.weixin.qq.com/connect/oauth2/authorize?appid=" +
						Appid + "&redirect_uri=" +
						encodeURIComponent(local) +
						"&response_type=code&scope=snsapi_userinfo&state=1#wechat_redirect";
				}
			},
			getAilCode: function() {
				//alert(code);
				let code = util.getUrlKey("auth_code"); //是否存在code
				let local = window.location.href;
				let Appid = "2021001140685915";
				if (code == null || code === "" || code==undefined) {
					window.location.href =
						"https://openauth.alipay.com/oauth2/publicAppAuthorize.htm?app_id=" +
						Appid + "&scope=auth_user&redirect_uri=" + encodeURIComponent(local) 

				} 
			},
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		}
	}
</script>
